package com.maiji.cloud.controller.shopingmall;

import java.util.List;

import com.maiji.cloud.utils.Unlogin;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.shopingmall.AddExchangeLogReqDto;
import com.maiji.cloud.request.shopingmall.GetExchangeLogReqDto;
import com.maiji.cloud.request.shopingmall.IntegralExchangeGoodsReqData;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.shopingmall.FreeDiscountCouponListResDto;
import com.maiji.cloud.response.shopingmall.GetDiscountCouponListResData;
import com.maiji.cloud.response.shopingmall.GetDiscountCouponListResDto;
import com.maiji.cloud.response.shopingmall.GetExchangeLogResDto;
import com.maiji.cloud.response.shopingmall.HaveDiscountCouponListResData;
import com.maiji.cloud.response.shopingmall.ShopingOrderResData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 优惠券 Description:
 * 
 * @author zhanglr
 * @date 2019年6月24日
 */
@RestController
@Api(tags = { "优惠券" })
@RequestMapping("/couponsInterface/")
public class CouponsController extends BaseController {
	/**
	 * 获去可兑换优惠券列表
	 * 
	 * @return
	 */
	@PostMapping("getDiscountCouponList")
	@ApiOperation(value = "获去可兑换优惠券列表")
	public GetDiscountCouponListResDto getDiscountCouponList(@RequestHeader String maijiToken) {
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<>(headers);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/getDiscountCouponList", httpEntity,
				GetDiscountCouponListResDto.class);
	}

	/**
	 * 获取积分兑换记录列表
	 * 
	 * @param getExchangeLogReqDto
	 * @return
	 */
	@PostMapping("getExchangeLogList")
	@ApiOperation(value = "获取积分兑换商品记录列表")
	public GetExchangeLogResDto getExchangeLogList(@RequestBody GetExchangeLogReqDto getExchangeLogReqDto,
			@RequestHeader String maijiToken) {
		getExchangeLogReqDto.setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/getExchangeLogList", getExchangeLogReqDto,
				GetExchangeLogResDto.class);
	}

	/**
	 * 积分兑换商品
	 * 
	 * @param param
	 * @return
	 */
	@PostMapping("integralExchangeGoods")
	@ApiOperation(value = "积分兑换商品")
	public BaseDataResDto<ShopingOrderResData> integralExchangeGoods(@RequestBody BaseDataReqDto<IntegralExchangeGoodsReqData> param,
			@RequestHeader("maijiToken") String maijiToken) {

		return postForObjectWithToken(maijiToken, REST_URL_SHOPINGMALL + "/shopingOrder/integralExchangeGoods", param,
				BaseDataResDto.class);

	}

	/**
	 * 用户兑换优惠券或免费领取
	 * 
	 * @param param
	 * @return
	 */
	@PostMapping("addExchangeLog")
	@ApiOperation(value = "领取优惠券")
	public BaseResDto addExchangeLog(@RequestBody AddExchangeLogReqDto param,
			@RequestHeader("maijiToken") String maijiToken) {
		param.setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/addExchangeLog", param, BaseDataResDto.class);
	}
	/**
	 * 可用优惠券列表
	 * 
	 * @return
	 */
	@PostMapping("getUsableDiscountCouponList")
	@ApiOperation(value = "用户已领取的优惠券列表")
	public BaseDataResDto<List<GetDiscountCouponListResData>> getUsableDiscountCouponList(
			@RequestBody BaseDataReqDto<Double> param, @RequestHeader String maijiToken) {

		return postForObjectWithToken(maijiToken, REST_URL_SHOPINGMALL + "/coupons/getUsableDiscountCouponList", param,
				BaseDataResDto.class);

	}

	/**
	 * 获取免费优惠券列表
	 * 
	 * @return
	 */
    @Unlogin
	@ApiOperation(value = "获取免费优惠券列表")
	@PostMapping("getfreeDiscountCouponList")
	public FreeDiscountCouponListResDto getfreeDiscountCouponList(@RequestBody BaseDataReqDto<Double> param
			) {
		return postForObjectWithToken(null, REST_URL_SHOPINGMALL + "/coupons/getfreeDiscountCouponList", param,
				FreeDiscountCouponListResDto.class);
	}

	/**
	 * 未领取优惠券
	 * 
	 * @return
	 */
	@ApiOperation(value = "获取未领取优惠券列表")
	@PostMapping("noPossessDiscountCouponList")
	public BaseDataResDto<List<GetDiscountCouponListResData>> noPossessDiscountCouponList(
			@RequestBody BaseDataReqDto<Double> param, @RequestHeader String maijiToken) {
		return postForObjectWithToken(maijiToken, REST_URL_SHOPINGMALL + "/coupons/noPossessDiscountCouponList", param,
				BaseDataResDto.class);
	}
	
	
	/**
	 * 1：未使用，2：已使用：3：已过期优惠券列表
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("getHaveDiscountCouponList")
	@ApiOperation(value = "1：未使用，2：已使用：3：已过期优惠券列表")
	public BaseDataResDto<List<HaveDiscountCouponListResData>> getHaveDiscountCouponList(@RequestBody BaseDataReqDto<Integer> param , @RequestHeader String maijiToken){
		return postForObjectWithToken(maijiToken, REST_URL_SHOPINGMALL + "/coupons/getHaveDiscountCouponList", param,
				BaseDataResDto.class);
	}

}
